{% extends 'admin-v2/layout.html.twig' %}

{% set menu = 'admin_v2_user_content_audit' %}

{% do script(['libs/bootstrap-datetimepicker.js','app/js/admin-v2/operating/user-content-audit/index.js']) %}

{% block main %}

  <form id="audit-search-form" class="form-inline well well-sm" action="" method="get" novalidate>

    <div class="form-group">
      <select class="form-control" name="targetType">
        {{ select_options(dict('userSelectedAuditTargetType'), app.request.query.get('targetType'), 'admin_v2.operation.user_content_audit_form.all_type_option'|trans) }}
      </select>
    </div>

    <div class="form-group">
      <select class="form-control" name="status">
        {{ select_options(dict('selectUserAuditStatus'), app.request.query.get('status')|default('none_checked'), {'all' :'admin_v2.operation.user_content_audit_form.all_status_option'|trans}) }}
      </select>
    </div>

    <div class="form-group">
      <select class="form-control" name="sensitiveWordsFilter">
        {{ select_options(dict('sensitiveWordsFilter'), app.request.query.get('sensitiveWordsFilter'), 'admin_v2.operation.user_content_audit_form.sensitive_words_filter_option'|trans) }}
      </select>
    </div>

    <div class="form-group">
      <input class="form-control" type="text"
             placeholder="{{ 'admin_v2.operation.user_content_audit_form.sensitive_keywords.placeholder'|trans }}"
             name="sensitiveWordsSearch" value="{{ app.request.get('sensitiveWordsSearch') }}">
    </div>

    <div class="form-group">
      <input class="form-control" type="text"
             placeholder="{{ 'admin_v2.operation.user_content_audit_form.author.placeholder'|trans }}" name="author"
             value="{{ app.request.get('author') }}">
    </div>

    <div class="form-group ">
      <input class="form-control" type="text" id="startTime" name="startTime"
             value="{{ app.request.query.get('startTime') }}"
             placeholder="{{ 'admin_v2.operation.user_content_audit_form.startTime'|trans }}" autocomplete="off">
      -
      <input class="form-control" type="text" id="endTime" name="endTime"
             value="{{ app.request.query.get('endTime') }}"
             placeholder="{{ 'admin_v2.operation.user_content_audit_form.endTime'|trans }}" autocomplete="off">
    </div>

    <button class="btn btn-primary">{{ 'form.btn.search'|trans }}</button>
  </form>


  <div id="audit-table-container">
    <table class="table table-striped table-hover audit-table" id="audit-table">
      <thead>
      <tr>
        <th width="4%"><input type="checkbox" data-role="batch-select"></th>
        <th width="40%">{{ 'admin_v2.operation.user_content_audit.content_th'|trans }}</th>
        <th width="20%">{{ 'admin_v2.operation.user_content_audit.contain_sensitive_words_th'|trans }}</th>
        <th>{{ 'admin_v2.operation.user_content_audit.type_th'|trans }}</th>
        <th>{{ 'admin_v2.operation.user_content_audit.author_time_th'|trans }}</th>
        <th>{{ 'admin_v2.operation.user_content_audit.status_th'|trans }}</th>
        <th>{{ 'admin_v2.operation.user_content_audit.auditor_th'|trans }}</th>
        <th>{{ 'admin_v2.operation.user_content_audit.operation_th'|trans }}</th>
      </tr>
      </thead>
      <tbody>
      {% for audit in userAudits %}
        {% set author = users[audit.author]|default(null) %}
        {% set auditor = users[audit.auditor]|default(null) %}
        <tr id="audit-table-tr-{{ audit.id }}" data-role="item">
          <td><input type="checkbox" value="{{ audit.id }}" data-role="batch-item"></td>
          <td>
            <div class="short-long-text">
              <div class="short-text">
                {{ audit.short_content|raw }} <span
                  class="text-muted trigger">({{ 'admin_v2.operation.user_content_audit.expand_td'|trans }})</span>
              </div>
              <div class="long-text">{{ audit.content|raw }} <span
                  class="text-muted trigger">({{ 'admin_v2.operation.user_content_audit.collapse_td'|trans }})</span>
              </div>
            </div>
          </td>
          <td>
            <div class="short-long-text">
              <div class="short-text">
                {{ audit.sensitiveWords|join(',')|plain_text(30) }} <span
                  class="text-muted trigger">({{ 'admin_v2.operation.user_content_audit.expand_td'|trans }})</span>
              </div>
              <div class="long-text">{{ audit.sensitiveWords|join(',')|nl2br }} <span
                  class="text-muted trigger">({{ 'admin_v2.operation.user_content_audit.collapse_td'|trans }})</span>
              </div>
            </div>
          </td>
          <td>{{ dict_text('userAuditTargetType', audit.targetType) }}</td>
          <td>
            {{ admin_macro.user_link(author)|default('') }}<br>
            <span class="text-muted">{{ audit.updatedTime|date('Y-n-d H:i') }}</span>
          </td>
          <td class="text-{{ audit.status }}" align="center">
            {{ dict_text('userAuditStatus', audit.status) }}
            {% if audit.auditor == '-1' %}
              <br/>
              ({{ '系统已审'|trans }})
            {% endif %}
          </td>

          <td>
            {% if audit.auditor == '-1' %}
              {{ 'admin_v2.operation.user_content_audit.default_auditor'|trans }}
            {% elseif audit.auditor != '0' %}
              {% set auditor = users[audit.auditor]|default([]) %}
              {{ admin_macro.user_link(auditor) }}<br>
            {% else %}
              --
            {% endif %}
          </td>
          <td>
            <a
              class="btn btn-sm btn-info operating-btn {% if 'pass' == audit.status %}hide{% endif %}"
              data-role="item-confirm-pass" data-name="{{ 'admin_v2.operation.user_content_audit.user_content'|trans }}"
              data-url="{{ path('admin_v2_user_content_audit_confirm', {id:audit.id,status:'pass'}) }}">
              {{ 'form.btn.confirm.normal'|trans }}
            </a>
            <a
              class="btn btn-sm btn-danger operating-btn {% if 'illegal' == audit.status %}hide{% endif %}"
              data-role="item-confirm-illegal"
              data-name="{{ 'admin_v2.operation.user_content_audit.user_content'|trans }}"
              data-url="{{ path('admin_v2_user_content_audit_confirm', {id:audit.id,status:'illegal'}) }}">
              {{ 'form.btn.confirm.illegal'|trans }}
            </a>
          </td>
        </tr>
      {% else %}
        <tr>
          <td colspan="20">
            <div class="empty">{{ 'site.datagrid.empty'|trans }}</div>
          </td>
        </tr>
      {% endfor %}
      </tbody>
    </table>

    <div>
      <label class="checkbox-inline">
        <input type="checkbox" data-role="batch-select"> {{ 'admin_v2.operation.user_content_audit.select_all_btn'|trans }}
      </label>
      <a class="btn btn-sm btn-info"
         data-url="{{ path('admin_v2_user_content_audit_batch_confirm', {status: 'pass'}) }}"
         data-status="pass" data-role="batch-confirm-pass"
         data-name="{{ 'admin_v2.operation.user_content_audit.user_content'|trans }}">
        {{ 'admin_v2.operation.audit_center.table.batch_pass'|trans }}
      </a>
      <a class="btn btn-sm btn-danger" data-status="illegal"
         data-url="{{ path('admin_v2_user_content_audit_batch_confirm' ,{status: 'illegal'}) }}"
         data-status="illegal" data-role="batch-confirm-illegal"
         data-name="{{ 'admin_v2.operation.user_content_audit.user_content'|trans }}">
        {{ 'admin_v2.operation.audit_center.table.batch_illegal'|trans }}
      </a>
    </div>
  </div>

  {{ admin_macro.paginator(paginator) }}
{% endblock %}
